//
//  AdvancedApproveVC.m
//  JinFuThree
//
//  Created by 毛韶谦 on 2018/9/1.
//  Copyright © 2018年 毛韶谦. All rights reserved.
//

#import "AdvancedApproveVC.h"
#import "IdentityCardView.h"
#import "ImportTextView.h"
#import "AddressBookTool.h"
#import "AdvancedApproveBankCardVC.h"
#import "IOSOCRAPI.h"
#import "SCCaptureCameraController.h"
#import "MyRequestTools.h"
#import <TZImagePickerController.h>

@interface AdvancedApproveVC ()<SCNavigationControllerDelegate, TZImagePickerControllerDelegate>

@property (nonatomic, strong) UIView *headerView;
@property (nonatomic, strong) UIScrollView *mainScrollView;
@property (nonatomic, strong) IdentityCardView *identityCardView;

@property (nonatomic, strong) ImportTextView *nameView;
@property (nonatomic, strong) ImportTextView *identityView;
@property (nonatomic, strong) ImportTextView *addressView;
@property (nonatomic, strong) ImportTextView *timeView;

@property (nonatomic, strong) ImportTextView *addressBookView;

@property (nonatomic, strong) UIButton *nextBtn;

@end

@implementation AdvancedApproveVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initUI];
    [self getInfot];
    // Do any additional setup after loading the view.
}

- (void)initUI {
    
    self.title = @"高级实名认证";
    self.mainScrollView.backgroundColor = ListMaoBackgroundColor;
    
    [self.identityCardView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(self.headerView);
        make.top.mas_equalTo(self.headerView.mas_bottom).offset(10);
        make.height.mas_equalTo(175);
    }];
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.textColor = HexColor(0x999999);
    titleLabel.font = [UIFont systemFontOfSize:13];
    titleLabel.text = @"请确认以下信息, 如若有误请更正";
    [self.mainScrollView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.headerView.mas_left).offset(20);
        make.right.mas_equalTo(self.headerView.mas_right).offset(-20);
        make.top.mas_equalTo(self.identityCardView.mas_bottom);
        make.height.mas_equalTo(35);
    }];
    
    [self.nameView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(self.headerView);
        make.top.mas_equalTo(titleLabel.mas_bottom);
        make.height.mas_equalTo(50);
    }];
    [self.identityView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(self.headerView);
        make.top.mas_equalTo(self.nameView.mas_bottom);
        make.height.mas_equalTo(50);
    }];
    [self.addressView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(self.headerView);
        make.top.mas_equalTo(self.identityView.mas_bottom).offset(10);
        make.height.mas_equalTo(50);
    }];
    [self.timeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(self.headerView);
        make.top.mas_equalTo(self.addressView.mas_bottom);
        make.height.mas_equalTo(50);
    }];
    [self.addressBookView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(self.headerView);
        make.top.mas_equalTo(self.timeView.mas_bottom).offset(10);
        make.height.mas_equalTo(50);
    }];
    [self.nextBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(self.view);
        make.height.mas_equalTo(50);
    }];
}


//授权通讯录
- (void)addressBookAction {
    
    [self.view endEditing:YES];
    [AddressBookTool LoadPersonAddressBookBlock:^(id obj) {
        
        [HFQIndicationView showInView:self.view];
        [MyRequestTools MyUserContactsWithParameters:obj Success:^(id  _Nullable responseObject) {
            [HFQIndicationView dismiss];
            //记录是否授权 tag 为 66；
            self.addressBookView.tag = 66;
            [self cheakData];
        } Failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
            [HFQIndicationView dismiss];
        }];
    }];
}

- (void)getInfot {
    
    [HFQIndicationView showInView:self.view];
    [MyRequestTools GetAdvancedApproveBasicWithParameters:nil Success:^(id  _Nullable responseObject) {
        [HFQIndicationView dismiss];
        NSDictionary *dataDic = responseObject[@"data"];
        NSString *frontUrl = dataDic[@"identityCardFrontImg"];
        if (frontUrl.length) {
            
            self.identityCardView.leftIdentityView.imageUrl = frontUrl;
            [self.identityCardView.leftIdentityView.identityImageView sd_setImageWithURL:[NSURL URLWithString:frontUrl]];
            self.identityCardView.leftIdentityView.removeBtn.tag = 11;
            self.identityCardView.leftIdentityView.removeBtn.hidden = NO;
            self.identityCardView.leftIdentityView.suspensionImageView.hidden = NO;
            self.identityCardView.leftIdentityView.cameraImageView.hidden = YES;
            self.identityCardView.leftIdentityView.hintLabel.hidden = YES;
        }
        NSString *reverseUrl = dataDic[@"identityCardReverseImg"];
        if (reverseUrl.length) {
            
            self.identityCardView.rightIdentityView.imageUrl = reverseUrl;
            [self.identityCardView.rightIdentityView.identityImageView sd_setImageWithURL:[NSURL URLWithString:reverseUrl]];
            self.identityCardView.rightIdentityView.removeBtn.hidden = NO;
            self.identityCardView.rightIdentityView.removeBtn.tag = 11;
            self.identityCardView.rightIdentityView.suspensionImageView.hidden = NO;
            self.identityCardView.rightIdentityView.cameraImageView.hidden = YES;
            self.identityCardView.rightIdentityView.hintLabel.hidden = YES;
        }
        self.identityView.leftTextView.text = dataDic[@"identityCardNumber"];
        self.timeView.leftTextView.text = dataDic[@"identityCardTerm"];
        self.addressView.leftTextView.text = dataDic[@"residenceAddress"];
        self.nameView.leftTextView.text = dataDic[@"userName"];
        if ([[NSString stringWithFormat:@"%@",dataDic[@"authorized"]] isEqualToString:@"1"]) {
            //记录是否授权 tag 为 66；
            self.addressBookView.tag = 66;
        }
        [self cheakData];
        
    } Failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
        [HFQIndicationView dismiss];
        
    }];
}


- (void)clickAction:(UITapGestureRecognizer *)sender {
    
    UIView *view = sender.view;
    [self showPickerView:view.tag];
}

//弹窗
-(void)showPickerView:(NSInteger)tag {
    
    
    self.identityCardView.tag = tag;
    
    UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidthMao, ScreenHeight)];
    backgroundView.backgroundColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.4/1.0];
    
    UIView *whiteView = [[UIView alloc] initWithFrame:CGRectMake(0, ScreenHeight - 210, ScreenWidthMao, 210)];
    whiteView.backgroundColor = HexColor(0xE7E7ED);
    [backgroundView addSubview:whiteView];
    
    UIButton *firstBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    firstBtn.backgroundColor = [UIColor whiteColor];
    firstBtn.frame = CGRectMake(0, 0, ScreenWidthMao, 50);
    [whiteView addSubview:firstBtn];
    
    UIButton *secondBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    secondBtn.tag = tag;
    secondBtn.backgroundColor = [UIColor whiteColor];
    secondBtn.frame = CGRectMake(0, 50.5f, ScreenWidthMao, 50);
    [secondBtn setTitle:@"拍摄/上传" forState:UIControlStateNormal];
    [secondBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    secondBtn.titleLabel.font = [UIFont systemFontOfSize:18];
    [secondBtn addTarget:self action:@selector(secondBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [whiteView addSubview:secondBtn];
    
    UIButton *thirdBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    thirdBtn.backgroundColor = [UIColor whiteColor];
    thirdBtn.tag = tag;
    thirdBtn.frame = CGRectMake(0, 101, ScreenWidthMao, 50);
    [thirdBtn setTitle:@"从相册选择照片" forState:UIControlStateNormal];
    [thirdBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    thirdBtn.titleLabel.font = [UIFont systemFontOfSize:18];
    [thirdBtn addTarget:self action:@selector(thirdBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [whiteView addSubview:thirdBtn];
    
    UIButton *bottomBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    bottomBtn.backgroundColor = [UIColor whiteColor];
    bottomBtn.frame = CGRectMake(0, 210 - 50, ScreenWidthMao, 50);
    [bottomBtn setTitle:@"取消" forState:UIControlStateNormal];
    [bottomBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    bottomBtn.titleLabel.font = [UIFont systemFontOfSize:18];
    [bottomBtn addTarget:self action:@selector(cancleBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [whiteView addSubview:bottomBtn];
    
    [UIView animateWithDuration:0.3 animations:^{
        [[HFQCommonTools lastWindow] addSubview:backgroundView];
    }];
    
}

- (void)secondBtnAction:(UIButton *)sender {
    
    [self cancleBtnAction:sender];
    [self showSCCaptureCameraController];
}

- (void)thirdBtnAction:(UIButton *)sender {
    
    TZImagePickerController *imgPickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:1 delegate:self];
    imgPickerVc.allowPickingVideo = NO;
    imgPickerVc.allowPickingGif = NO;
    imgPickerVc.allowPickingMultipleVideo = NO;
    imgPickerVc.naviBgColor = ThemeMaoColor;
    [imgPickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> * photos, NSArray *assets, BOOL result) {
        for (UIImage *image in photos)
        {
            [self identityCardInfoRecognitionWithIamge:image];
            [ASJF_Service uploadPictureWithData:image Success:^(id  _Nullable responseObject) {
                
                NSString *url = responseObject[@"data"][@"filePath"];
                switch (self.identityCardView.tag) {
                    case 11:
                    {
                        self.identityCardView.leftIdentityView.imageUrl = url;
                        [self.identityCardView.leftIdentityView.identityImageView sd_setImageWithURL:[NSURL URLWithString:url]];
                        self.identityCardView.leftIdentityView.removeBtn.tag = 11;
                        self.identityCardView.leftIdentityView.removeBtn.hidden = NO;
                        self.identityCardView.leftIdentityView.suspensionImageView.hidden = NO;
                        self.identityCardView.leftIdentityView.cameraImageView.hidden = YES;
                        self.identityCardView.leftIdentityView.hintLabel.hidden = YES;
                    }
                        break;
                    case 12:
                    {
                        self.identityCardView.rightIdentityView.imageUrl = url;
                        [self.identityCardView.rightIdentityView.identityImageView sd_setImageWithURL:[NSURL URLWithString:url]];
                        self.identityCardView.rightIdentityView.removeBtn.hidden = NO;
                        self.identityCardView.rightIdentityView.removeBtn.tag = 11;
                        self.identityCardView.rightIdentityView.suspensionImageView.hidden = NO;
                        self.identityCardView.rightIdentityView.cameraImageView.hidden = YES;
                        self.identityCardView.rightIdentityView.hintLabel.hidden = YES;
                    }
                        break;
                        
                    default:
                        break;
                }
                [self cheakData];
                
            } Failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
                
            }];
        }
    }];
    [self presentViewController:imgPickerVc animated:YES completion:nil];
    [self cancleBtnAction:sender];
}

- (void)cancleBtnAction:(UIButton *)sender {
    
    
    UIView *whiteView = sender.superview;
    UIView *backgroundView = whiteView.superview;
    
    [UIView animateWithDuration:0.3 animations:^{
        backgroundView.alpha = 0;
    } completion:^(BOOL finished) {
        backgroundView.hidden = YES;
        [backgroundView removeFromSuperview];
    }];
}

#pragma mark ------ 身份证识别-------
- (void)identityCardInfoRecognitionWithIamge:(UIImage *)image {
    [HFQIndicationView showInView:self.view];
    Gint ret = 0;
    Gint vaule = 1;
    ret = TREC_StartUP(TREC_GetEngineTimeKEY());
    if (ret == 100) {
        NSLog(@"引擎过期\n");
//        [HUD_Mao showCharacterMessage:@"身份证信息识别失败"];
        [HFQIndicationView dismiss];
        return;
    }
    ret = TREC_SetParam(T_SET_HEADIMG, &vaule);
    ret = TREC_SetSupportEngine(TIDCARD2);
    if (ret != 1) {
        NSLog(@"引擎不支持\n");
        TREC_ClearUP();
//        [HUD_Mao showCharacterMessage:@"身份证信息识别失败"];
        [HFQIndicationView dismiss];
        return;
    }
    ret = TREC_LoadImage(image);
    ret = TREC_OCR();
    ret = TREC_FreeImage();
    NSString * allinfo = TREC_GetOcrString();
    NSLog(@"%@\n",allinfo);
    
    NSString * name = TREC_GetFieldString(NAME);
    NSString * num = TREC_GetFieldString(NUM);
    NSString * address = TREC_GetFieldString(ADDRESS);
    NSString * time = TREC_GetFieldString(PERIOD);
    
    if (self.identityCardView.tag == 11) {
        
        self.nameView.leftTextView.text = name;
        self.identityView.leftTextView.text = num;
        self.addressView.leftTextView.text = address;
    }else if (self.identityCardView.tag == 12) {
        
        self.timeView.leftTextView.text = time;
    }
        
    NSLog(@"%@\n %@\n %@\n %@",name,num,address,time);

    ret = TREC_ClearUP();
    [self cheakData];
    [HFQIndicationView dismiss];
}
- (void)showSCCaptureCameraController {
    [HFQIndicationView showInView:self.view];
    SCCaptureCameraController *con = [[SCCaptureCameraController alloc] init];
    con.scNaigationDelegate = self;
    con.isDisPlayTxt = YES;
    con.ScanMode = TIDC_SCAN_MODE;
    con.iCardType = TIDCARD2;
    [HFQIndicationView dismiss];
    [self presentViewController:con animated:YES completion:NULL];
}
- (void)sendIDCBackValue:(NSString *)issue PERIOD:(NSString *) period {
    
    self.timeView.leftTextView.text = period;
    [self cheakData];
    NSLog(@"%@",period);
}
- (void)sendTakeImage:(TCARD_TYPE) iCardType image:(UIImage *)cardImage {
    
    
    [ASJF_Service uploadPictureWithData:cardImage Success:^(id  _Nullable responseObject) {
        
        NSString *url = responseObject[@"data"][@"filePath"];
        switch (self.identityCardView.tag) {
            case 11:
            {
                self.identityCardView.leftIdentityView.imageUrl = url;
                [self.identityCardView.leftIdentityView.identityImageView sd_setImageWithURL:[NSURL URLWithString:url]];
                self.identityCardView.leftIdentityView.removeBtn.tag = 11;
                self.identityCardView.leftIdentityView.removeBtn.hidden = NO;
                self.identityCardView.leftIdentityView.suspensionImageView.hidden = NO;
                self.identityCardView.leftIdentityView.cameraImageView.hidden = YES;
                self.identityCardView.leftIdentityView.hintLabel.hidden = YES;
            }
                break;
            case 12:
            {
                self.identityCardView.rightIdentityView.imageUrl = url;
                [self.identityCardView.rightIdentityView.identityImageView sd_setImageWithURL:[NSURL URLWithString:url]];
                self.identityCardView.rightIdentityView.removeBtn.hidden = NO;
                self.identityCardView.rightIdentityView.removeBtn.tag = 11;
                self.identityCardView.rightIdentityView.suspensionImageView.hidden = NO;
                self.identityCardView.rightIdentityView.cameraImageView.hidden = YES;
                self.identityCardView.rightIdentityView.hintLabel.hidden = YES;
            }
                break;
                
            default:
                break;
        }
        [self cheakData];
        
    } Failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
        
    }];
}
- (void)sendIDCValue:(NSString *)name SEX:(NSString *)sex FOLK:(NSString *)folk BIRTHDAY:(NSString *)birthday ADDRESS:(NSString *) address NUM:(NSString *)num {
    
    self.nameView.leftTextView.text = name;
    self.identityView.leftTextView.text = num;
    self.addressView.leftTextView.text = address;
    
    [self cheakData];
}



- (void)nextAction:(UIButton *)sender {
    
    NSMutableDictionary *mutDic = [NSMutableDictionary dictionary];
    
    [mutDic setObject:self.identityCardView.leftIdentityView.imageUrl forKey:@"identityCardFrontImg"];
    [mutDic setObject:self.identityView.leftTextView.text forKey:@"identityCardNumber"];
    [mutDic setObject:self.identityCardView.rightIdentityView.imageUrl forKey:@"identityCardReverseImg"];
    [mutDic setObject:self.timeView.leftTextView.text forKey:@"identityCardTerm"];
    [mutDic setObject:self.addressView.leftTextView.text forKey:@"residenceAddress"];
    [mutDic setObject:self.nameView.leftTextView.text forKey:@"userName"];
    
    [HFQIndicationView showInView:self.view];
    [MyRequestTools AdvancedApproveBasicWithParameters:mutDic Success:^(id  _Nullable responseObject) {
        [HFQIndicationView dismiss];
        
        AdvancedApproveBankCardVC *vc = [[AdvancedApproveBankCardVC alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
        
    } Failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
        [HFQIndicationView dismiss];
        
        
    }];
}


- (void)cheakData {
    
    self.nextBtn.alpha = 0.5f;
    self.nextBtn.userInteractionEnabled = NO;
    if (!self.identityCardView.leftIdentityView.imageUrl.length) {
        
        return;
    }else if (!self.identityCardView.rightIdentityView.imageUrl.length) {
        
        return;
    }else if (!self.identityView.leftTextView.text.length) {
        
        return;
    }else if (!self.timeView.leftTextView.text.length) {
        
        return;
    }else if (!self.addressView.leftTextView.text.length) {
        
        return;
    }else if (!self.nameView.leftTextView.text.length) {
        
        return;
    }else if (![[NSPredicate predicateWithFormat:@"SELF MATCHES %@",@"^\\d{16}$"] evaluateWithObject:[HFQCommonTools dislodgeStringSpecialChar:self.timeView.leftTextView.text]]) {
        
        return;
    }else if (self.addressBookView.tag != 66) {//记录是否授权 tag 为 66；
        
        return;
    }
    self.nextBtn.alpha = 1;
    self.nextBtn.userInteractionEnabled = YES;
}

//检测姓名、身份证、地址
- (void)textFieldChanged:(UITextField *)textField {
    
    [self cheakData];
}
//检测有效期
- (void)textFieldValueChanged:(UITextField *)textField {
    
    textField.text = [self identityCardDateStandardization:textField.text];
    
    [self cheakData];
}

//2018.01.01-2017.01.01
- (NSString *)identityCardDateStandardization:(NSString *)dateStr {
    
    NSMutableString *mutStr = [dateStr mutableCopy];
    
    if (mutStr.length) {
        
        NSString *passwordStandard = @"^[0-9]+$";
        NSRegularExpression *regexpasswordStandard = [NSRegularExpression regularExpressionWithPattern:passwordStandard options:0 error:nil];
        
        NSTextCheckingResult *isMatchpasswordStandard = [regexpasswordStandard firstMatchInString:mutStr options:0 range:NSMakeRange(mutStr.length-1, 1)];
        
        if (isMatchpasswordStandard) { //符合要求
            
            if ([[dateStr substringWithRange:NSMakeRange(mutStr.length-1, 1)] isEqualToString:@"."]) {
                [mutStr deleteCharactersInRange:NSMakeRange(mutStr.length-1, 1)];
                
            }else if ([[dateStr substringWithRange:NSMakeRange(mutStr.length-1, 1)] isEqualToString:@"-"]) {
                [mutStr deleteCharactersInRange:NSMakeRange(mutStr.length-1, 1)];
                
            }else {
                if (dateStr.length > 4 && ![[dateStr substringWithRange:NSMakeRange(4, 1)] isEqualToString:@"."]) {
                    [mutStr insertString:@"." atIndex:4];
                }
                if (dateStr.length > 7 && ![[dateStr substringWithRange:NSMakeRange(7, 1)] isEqualToString:@"."]) {
                    [mutStr insertString:@"." atIndex:7];
                }
                if (dateStr.length > 10 && ![[dateStr substringWithRange:NSMakeRange(10, 1)] isEqualToString:@"-"]) {
                    [mutStr insertString:@"-" atIndex:10];
                }
                if (dateStr.length > 15 && ![[dateStr substringWithRange:NSMakeRange(15, 1)] isEqualToString:@"."]) {
                    [mutStr insertString:@"." atIndex:15];
                }
                if (dateStr.length > 18 && ![[dateStr substringWithRange:NSMakeRange(18, 1)] isEqualToString:@"."]) {
                    [mutStr insertString:@"." atIndex:18];
                }
            }
            
            dateStr = mutStr;
            
        }else {
            dateStr = [dateStr substringToIndex:mutStr.length - 1];
        }
    }
    
    if (dateStr.length > 21) {
        
        dateStr = [dateStr substringToIndex:21];
    }
    
    return dateStr;
}


- (UIScrollView *)mainScrollView {
    
    if (!_mainScrollView) {
        _mainScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidthMao, ScreenHeight - SafeAreaTopHeight)];
        _mainScrollView.contentSize = CGSizeMake(ScreenWidthMao, 600);
        _mainScrollView.showsVerticalScrollIndicator = NO;
        _mainScrollView.showsHorizontalScrollIndicator = NO;
        _mainScrollView.bounces = NO;
        
        [self.view addSubview:_mainScrollView];
    }
    return _mainScrollView;
}


- (UIView *)headerView {
    
    if (!_headerView) {
        _headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidthMao, 55)];
        _headerView.backgroundColor = [UIColor whiteColor];
        [self.mainScrollView addSubview:_headerView];
        
        UIImageView *lineImageView = [[UIImageView alloc] init];
        lineImageView.backgroundColor = HexColor(0xBA915E);
        [_headerView addSubview:lineImageView];
        [lineImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(57, 0.5f));
            make.centerX.centerY.mas_equalTo(_headerView);
        }];
        
        UILabel *leftLabel = [[UILabel alloc] init];
        leftLabel.text = @"身份信息";
        leftLabel.textColor = HexColor(0x383838);
        leftLabel.font = [UIFont systemFontOfSize:13];
        [_headerView addSubview:leftLabel];
        [leftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(_headerView);
            make.right.mas_equalTo(lineImageView.mas_left).offset(-8);
        }];
        
        UILabel *leftLogoLabel = [[UILabel alloc] init];
        leftLogoLabel.text = @"1";
        leftLogoLabel.textColor = [UIColor whiteColor];
        leftLogoLabel.backgroundColor = ThemeMaoColor;
        leftLogoLabel.layer.cornerRadius = 7.5;
        leftLogoLabel.layer.masksToBounds = YES;
        leftLogoLabel.font = [UIFont systemFontOfSize:13];
        [leftLogoLabel setTextAlignment:NSTextAlignmentCenter];
        [_headerView addSubview:leftLogoLabel];
        [leftLogoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(_headerView);
            make.right.mas_equalTo(leftLabel.mas_left).offset(-8);
            make.size.mas_equalTo(CGSizeMake(15, 15));
        }];
        
        UILabel *rightLogoLabel = [[UILabel alloc] init];
        rightLogoLabel.text = @"2";
        rightLogoLabel.textColor = [UIColor whiteColor];
        rightLogoLabel.backgroundColor = HexColor(0xaaaaaa);
        rightLogoLabel.layer.cornerRadius = 7.5;
        rightLogoLabel.layer.masksToBounds = YES;
        rightLogoLabel.font = [UIFont systemFontOfSize:13];
        [rightLogoLabel setTextAlignment:NSTextAlignmentCenter];
        [_headerView addSubview:rightLogoLabel];
        [rightLogoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(_headerView);
            make.left.mas_equalTo(lineImageView.mas_right).offset(8);
            make.size.mas_equalTo(CGSizeMake(15, 15));
        }];
        
        UILabel *rightLabel = [[UILabel alloc] init];
        rightLabel.text = @"银行卡信息";
        rightLabel.textColor = HexColor(0x999999);
        rightLabel.font = [UIFont systemFontOfSize:13];
        [_headerView addSubview:rightLabel];
        [rightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(_headerView);
            make.left.mas_equalTo(rightLogoLabel.mas_right).offset(8);
        }];
        
    }
    return _headerView;
}

- (IdentityCardView *)identityCardView {
    
    if (!_identityCardView) {
        _identityCardView = [[IdentityCardView alloc] init];
        UITapGestureRecognizer *tap11 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickAction:)];
        UITapGestureRecognizer *tap12 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickAction:)];
        _identityCardView.leftIdentityView.tag = 11;
        _identityCardView.rightIdentityView.tag = 12;
        [_identityCardView.leftIdentityView addGestureRecognizer:tap11];
        [_identityCardView.rightIdentityView addGestureRecognizer:tap12];
        
        [self.mainScrollView addSubview:_identityCardView];
    }
    return _identityCardView;
}

- (ImportTextView *)nameView {
    
    if (!_nameView) {
        _nameView = [[ImportTextView alloc] init];
        _nameView.leftTextView.placeholder = @"身份证姓名";
        _nameView.titleLabel.text = @"姓      名";
        [_nameView.leftTextView addTarget:self action:@selector(textFieldChanged:) forControlEvents:UIControlEventEditingChanged];
        
        [self.mainScrollView addSubview:_nameView];
    }
    return _nameView;
}
- (ImportTextView *)identityView {
    
    if (!_identityView) {
        _identityView = [[ImportTextView alloc] init];
        _identityView.leftTextView.placeholder = @"18位身份证号";
        _identityView.titleLabel.text = @"身份证号";
        _identityView.lineImageView.hidden = YES;
        [_identityView.leftTextView addTarget:self action:@selector(textFieldChanged:) forControlEvents:UIControlEventEditingChanged];
        
        [self.mainScrollView addSubview:_identityView];
    }
    return _identityView;
}
- (ImportTextView *)addressView {
    
    if (!_addressView) {
        _addressView = [[ImportTextView alloc] init];
        _addressView.leftTextView.placeholder = @"身份证地址";
        _addressView.titleLabel.text = @"证件地址";
        [_addressView.leftTextView addTarget:self action:@selector(textFieldChanged:) forControlEvents:UIControlEventEditingChanged];
        
        [self.mainScrollView addSubview:_addressView];
    }
    return _addressView;
}
- (ImportTextView *)timeView {
    
    if (!_timeView) {
        _timeView = [[ImportTextView alloc] init];
        _timeView.leftTextView.placeholder = @"例:2010.01.01-2020.01.01";
        [_timeView.leftTextView addTarget:self action:@selector(textFieldValueChanged:) forControlEvents:UIControlEventEditingChanged];
        _timeView.titleLabel.text = @"有效期范围";
        [_timeView.leftTextView setKeyboardType:UIKeyboardTypeNumberPad];
        _timeView.lineImageView.hidden = YES;
        
        [self.mainScrollView addSubview:_timeView];
    }
    return _timeView;
}
- (ImportTextView *)addressBookView {
    
    if (!_addressBookView) {
        _addressBookView = [[ImportTextView alloc] init];
        _addressBookView.leftTextView.textColor = HexColor(0x0076FF);
        _addressBookView.leftTextView.text = @"获取通讯录";
        _addressBookView.titleLabel.text = @"通讯录授权";
        _addressBookView.lineImageView.hidden = YES;
        
        [self.mainScrollView addSubview:_addressBookView];
        
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
        [btn addTarget:self action:@selector(addressBookAction) forControlEvents:UIControlEventTouchUpInside];
        [_addressBookView addSubview:btn];
        [btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.bottom.right.mas_equalTo(_addressBookView);
        }];
    }
    return _addressBookView;
}

- (UIButton *)nextBtn {
    
    if (!_nextBtn) {
        _nextBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_nextBtn addTarget:self action:@selector(nextAction:) forControlEvents:UIControlEventTouchUpInside];
        _nextBtn.alpha = 0.5f;
        _nextBtn.userInteractionEnabled = NO;
        CAGradientLayer *gradientLayer = [CAGradientLayer layer];
        gradientLayer.colors = @[(__bridge id)HexColor(0xD6C096).CGColor, (__bridge id)HexColor(0xBEA471).CGColor];
        gradientLayer.locations = @[@0, @1];
        gradientLayer.startPoint = CGPointMake(0, 1);
        gradientLayer.endPoint = CGPointMake(1, 1);
        gradientLayer.frame = CGRectMake(0, 0, ScreenWidthMao, 50);
        gradientLayer.cornerRadius = 4;
        gradientLayer.masksToBounds = YES;
        [_nextBtn.layer addSublayer:gradientLayer];
        
        UILabel *label = [[UILabel alloc] init];
        label.font = [UIFont systemFontOfSize:15];
        label.textColor = [UIColor whiteColor];
        label.text = @"下一步";
        [_nextBtn addSubview:label];
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.centerY.mas_equalTo(_nextBtn);
        }];
        
        [self.view addSubview:_nextBtn];
    }
    return _nextBtn;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
